class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution:
    """
    思路：二叉树最大深度为左子树深度+根节点或右子树深度+根节点，故求出左子树和右子树深度，比较后+1即可
    """
    def max_depth(self, root: TreeNode) -> int:
        if root is None:
            return 0
        # 求左子树深度
        left_depth = self.max_depth(root.left)
        # 求右子树深度
        right_depth = self.max_depth(root.right)
        # 返回最大深度
        return max(left_depth, right_depth) + 1
